<%@ page language="java" contentType="text/javascript; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import='java.sql.*' %>
<%@page import="java.util.ArrayList"%>
<%@page import="net.sf.json.JSONObject"%>
<%@page import="net.sf.json.JSONSerializer"%>
<%@page import="net.sf.json.JSONArray"%>

<%
	response.setHeader("Access-Control-Allow-Origin", "*");
	response.setHeader("Access-Control-Allow-Headers", "x-requested-with");
	request.setCharacterEncoding("UTF-8");	
	String id = request.getParameter("id");
	String name = request.getParameter("name");
	//String name = new String(request.getParameter("name").getBytes("8859_1"), "utf-8"); 
	String email = request.getParameter("email");
	String age = request.getParameter("age");
	String gender = request.getParameter("gender");
	String jointheme = request.getParameter("jointheme");
	String cacao = request.getParameter("cacao");
	
	//String cacao = new String(request.getParameter("cacao").getBytes("8859_1"), "utf-8");
	String userlat = request.getParameter("userlat");
	String userlng = request.getParameter("userlng");
	
	
	Connection conn = null;
	PreparedStatement pstmt = null;
	
	try{
		Class.forName("com.mysql.jdbc.Driver");
		conn = DriverManager.getConnection(
			"jdbc:mysql://localhost/itscreater", "itscreater", 

"campus123");
		
		String insert = "insert into UserInfoCopy" +
						"(ID, Name, Email, Age, Gender, Cacao, UserTheme, UserTime, UserLat, UserLng) " +
						"values (?, ?, ?, ?, ?, ?, ?, NOW(), ?, ?);";
		pstmt = conn.prepareStatement(insert);
		pstmt.setString(1, id);
		pstmt.setString(2, name);
		pstmt.setString(3, email);
		pstmt.setString(4, age);
		pstmt.setString(5, gender);
		pstmt.setString(6, cacao);
		pstmt.setString(7, jointheme);
		pstmt.setString(8, userlat);
		pstmt.setString(9, userlng);
		pstmt.executeUpdate();
		
		JSONObject jo = new JSONObject();		
		jo.put("success", "true");

		out.print(jo);
	}
	
	finally{
		try{
			pstmt.close();
		}
		catch (Exception ignored){
		}
		try{
			conn.close();
		}
		catch (Exception ignored){
		}
	}
%>